﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AuctionSystem.AuctionService;
using System.ServiceModel;

namespace AuctionSystem
{
    public partial class Login : Form
    {
        private static AuctionServiceClient client;

        public Login()
        {
            InitializeComponent();
            client = new AuctionServiceClient();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            var password = textBox2.Text;

            if (username == null || username == "")
            {
                throw new FaultException("You have to type a username");
            }

            if (password == null || password == "")
            {
                throw new FaultException("You have to type a password");
            }

            User temUser = new User();
            try 
            { 
            temUser = client.Login(username, password);
            }
            catch
            {
                MessageBox.Show("Wrong Username or Password");
            }

            if (temUser != null)
            {
                Index indexShow = new Index();
                indexShow.Show();
                //this.Close();
            }
            else
            {
                MessageBox.Show("Please enter valid information");
            }
        }
    }
}
